package model.dao;

import model.entity.Book;
import org.junit.Test;
import org.springframework.jdbc.core.JdbcTemplate;

import java.sql.Date;

public class ModDaoImpl implements ModDao{
    private JdbcTemplate template;

    public ModDaoImpl(JdbcTemplate template) {
        this.template = template;
    }
    public ModDaoImpl() {
        this.template = new JdbcTemplate(BaseDao.getDataSource());
    }

    @Override
    public void mod(Book book) {
        String bookNo=book.getBookNo();
        String bookName=book.getBookName();
        String press=book.getPress();
        Date pubTime=book.getPubTime();
        String author=book.getAuthor();
        String location=book.getLocation();
        double price=book.getPrice();
        boolean isBorrowed=book.isBorrowed();
        String sql="update books set bookName=?,press=?,pubTime=?,author=?,location=?" +
                ",price=?,isBorrowed=? where bookNo=?";
        int count=template.update(sql,bookName,press,pubTime,author,location,price,isBorrowed,bookNo);
        System.out.println(count);
    }

    @Test
    public void test()
    {
        Book book=new Book("2","22222","1",new Date(1-1-1),"1","1",1,false);
        mod(book);
    }
}
